<?php

namespace app\system\controller;

use app\common\controller\Oauth;
use external\SFTools;

class Auth02 extends Oauth{

    public function initialize(){
        parent::initialize();
    }
    
    public function index() {
        return $this->fetch();
    }
    
    public function dispatch() {
        return $this->fetch();
    }
    
    public function exportExcel() {
        if (!request()->isPost()) {
            $this->error(SFTools::err_msg('3301'));
            exit;
        }
        $data = input('post.');
        $keyword = htmlspecialchars($data['keyword']);
        $fPlanDate = htmlspecialchars($data['fPlanDate']);
        $fStartDate = htmlspecialchars($data['fStartDate']);
        $fEndDate = htmlspecialchars($data['fEndDate']);
        $cw = htmlspecialchars($data['cw']);
        $ct = htmlspecialchars($data['ct']);
        $wg = htmlspecialchars($data['wg']);
    
        $dispatchLogic = new \backend\logic\DispatchLogic;
        $result = $dispatchLogic->exportExcel($keyword, $fPlanDate, $fStartDate, $fEndDate, $cw, $ct, $wg);
        
        if ($result === false) {
            $this->error(SFTools::err_msg('3601'));
            exit;
        }
    }
    
    public function importExcel() {
        if (!request()->isPost()) {
            $this->error(SFTools::err_msg('3301'));
            exit;
        }
        $fFileFind = $_FILES['uploadFile'];
    
        $dispatchLogic = new \backend\logic\DispatchLogic;
        $result = $dispatchLogic->importExcel($fFileFind);
    
        if (empty($result['error_code'])) {
            $msg = '更新排序成功 ' . $result['succ'] . '行；更新排序失败 ' . $result['fail'] . '行；';
            $this->success($msg, '/system/Auth02/dispatch');
        } else {
            $this->error(SFTools::err_msg($result['error_code']));
        }
    }
    
    public function exportPDF() {
        if (!request()->isPost()) {
            $this->error(SFTools::err_msg('3301'));
            exit;
        }
        $data = input('post.');
        $fGoodsID = htmlspecialchars($data['fGoodsID']);
        $fProcessCW = htmlspecialchars($data['fProcessCW']);
        $fQtyCW = htmlspecialchars($data['fQtyCW']);
        
        $dispatchLogic = new \backend\logic\DispatchLogic;
        $result = $dispatchLogic->exportPDF($fGoodsID, $fProcessCW, $fQtyCW);
        
        if ($result === false) {
            $this->error(SFTools::err_msg('3601'));
            exit;
        }
    }
}
